import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;



public class PolicyAlterApply {
	/**
	 * @Fields PROPERTIES_NAME : 资源配置文件的名称
	 */
	private static String PROPERTIES_NAME = "jdbc";

	private static PropertyResourceBundle properTyResourceBundle;
	static {
		properTyResourceBundle = (PropertyResourceBundle) ResourceBundle.getBundle(PROPERTIES_NAME);
	}

	/**
	 * 读取某个文件夹下的所有文件
	 */
	public static boolean readfile(String filepath)
			throws FileNotFoundException, IOException {
		System.out.println("begin time:"+new Date());
		InputStreamReader fr = null;  
		BufferedReader br = null;  
        try {  
            fr = new InputStreamReader(new FileInputStream(filepath));  
            br = new BufferedReader(fr);  
            String rec = null;  
            String[] argsArr = null;  
            List<String> policyAlterlist = new ArrayList<String>();
            List<String> policylist = new ArrayList<String>();
            String title = br.readLine();
            System.out.println(title);
            while ((rec = br.readLine()) != null) {  
                argsArr = rec.split(",");
                String policyNo = argsArr[0].substring(1, argsArr[0].length()-1);
                String eorderNo = argsArr[1].substring(1, argsArr[1].length()-1);
                String status = argsArr[2].substring(1, argsArr[2].length()-1);
                String type = argsArr[3].substring(1, argsArr[3].length()-1);
                String money = argsArr[4].substring(1, argsArr[4].length()-1);
                if(status.equals("0")){
                	String updatesql  = "update tbl_policy_alter_apply set apply_status = 4,alter_status = 1," +
                			" ACTUAL_RETURN_MONEY = "+money+" where BATCH_NO = '"+eorderNo+"'";
                	policyAlterlist.add(updatesql);
                	if(!type.equals("AR")){
                		String policysql  = "update tbl_policy set POLICY_STATUS = 5 where POLICY_NO = '"+policyNo+"'";
                		policylist.add(policysql);
                	}
                }else{
                	String updatesql  = "update tbl_policy_alter_apply set apply_status = 31,alter_status = 3 " +
                			"where BATCH_NO = '"+eorderNo+"'";
                	policyAlterlist.add(updatesql);
                }
            }
            DBConnection connection = new DBConnection();//数据连接
            connection.controllerTable(policyAlterlist);
			System.out.println("修改保全表完毕"+new Date());
            connection.controllerTable(policylist);
			System.out.println("修改保单表完毕"+new Date());
			System.out.println("end time:"+new Date());
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (fr != null)  
                    fr.close();  
                if (br != null)  
                    br.close();  
            } catch (IOException ex) {  
                ex.printStackTrace();  
            }  
        }
		return true;
	}
	

	public static void main(String[] args) {
		try {
			String file = properTyResourceBundle.getString("filepath");
			readfile(file);
		}  catch (Exception ex) {
			ex.printStackTrace();
		}
		System.out.println("ok");
	}
}
